﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Text;
using System.Threading.Tasks;
using WCFService;
using WCFStudy;

namespace WcfStudyServerConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            //暴露服务
            using (ServiceHost host = new ServiceHost(typeof(CalculatorService)))
            {
                ////添加服务契约、传输方式、服务地址,配置服务端
                //host.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), "http://127.0.0.1:9999/calculatorservice");
                ////创建服务行为描述元数据，将服务的配置以元数据方式通知客户端。
                //if (host.Description.Behaviors.Find<ServiceMetadataBehavior>() == null)
                //{
                //    ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior();
                //    metadataBehavior.HttpGetEnabled = true;
                //    metadataBehavior.HttpGetUrl = new Uri("http://127.0.0.1:9999/calculatorservice");
                //    host.Description.Behaviors.Add(metadataBehavior);
                //}
                host.Opened += delegate
                {
                    Console.WriteLine("服务已启动，如需要结束服务请输入任何按钮！");
                };
                //发布服务
                host.Open();

                //保持宿主进程及服务容器的存活,如使用using语法,则必须在using中保持服务容器的存活。
                //如果将Console.Read()移出using外面，则服务容器就会被垃圾回收器回收。

                Console.Read();

            }
        }
    }
}
